package com.bank.code;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;


public class RespCode {
	  protected static HashMap<String, RespCode> allCodes = new HashMap<String, RespCode>();

	    public static RespCode SUCCESS = new RespCode("00000", "处理成功");
	    public static RespCode ACCEPT_SUCCESS = new RespCode("00001", "处理成功");

	    /** 数据库异常类 */
	    public static RespCode FAIL_DB_INIT = new RespCode("91001", "入库失败");
	    public static RespCode RECORD_EXISTED = new RespCode("91002", "数据插入重复");
	    public static RespCode RECORD_NOT_EXIST = new RespCode("91003", "查询无符合条件记录");
	    public static RespCode DB_UPDATE_ZERO = new RespCode("91004", "数据未更新");
	    public static RespCode FAIL_DB_UPDATE = new RespCode("91005", "更新失败");
	    public static RespCode FAIL_DB = new RespCode("91099", "数据库操作失败");

	    /** 异常处理类 */
	    public static RespCode EXCEPTION_DEAL_DOING = new RespCode("70001", "异常正在处理中");
	    public static RespCode EXCEPTION_DEAL_DONE = new RespCode("70002", "异常已处理");
	    public static RespCode EXCEPTION_DEAL_FAILD = new RespCode("70003", "异常处理失败");
	    public static RespCode HOST_RECHECK = new RespCode("70004", "待人工复核 ");

	    public static RespCode ACCT_IS_DOUBTFUL = new RespCode("93001", "账号可疑");
	    public static RespCode ACCT_IS_BLACK = new RespCode("93002", "账号黑名单");
	    
	    public static RespCode ACCT_IS_EXCEPTION = new RespCode("93002", "账号异常");

	    
	    public static RespCode LACK_OF_BALANCE  = new RespCode("10001", "余额不足");
	    
	    public static RespCode LESS_CONFIGURATION  = new RespCode("20001", "未配置");

	    
	    public static RespCode ACCT_ISNOT_EXISTS  = new RespCode("10002", "账号未配置");
	    
	    
	    public static RespCode ACCT_STATUS_NOT_CORRECT  = new RespCode("10003", "账号状态不正确");
	    
	    public static RespCode PASSWORD_NOT_CORRECT  = new RespCode("10004", "密码不正确");
	    
	    public static RespCode PASSWORD_ENCRYPT_FAIL  = new RespCode("20001", "加密失败");
	    public static RespCode USER_NOT_EXIST  = new RespCode("20002", "柜员名称不存在");
	    public static RespCode TELLER_IS_EXIST  = new RespCode("20003", "柜员已存在");
	    public static RespCode SYSTEM_FAILUE  = new RespCode("30001", "系统错误");
	    public static RespCode ORGAN_IS_EXIST  = new RespCode("20003", "机构号已存在");
	    public static RespCode ORGAN_NOT_EXIST  = new RespCode("20004", "机构不存在");
	    public static RespCode SUB_IS_EXIST  = new RespCode("20005", "科目号已存在");
	    public static RespCode SUB_NOT_EXIST  = new RespCode("20006", "科目存在");


	    protected String code;
	    protected String msg;
	    protected static String sysCode;

	    public RespCode(String code, String msg) {
	        this.code = code;
	        this.msg = msg;
	    }

	    public String getRespCode() {
	        return code;
	    }
	    
	    public String getCode(){
	        return code;
	    }

	    public String getMessage() {
	        return msg;
	    }
	    
	    @Override
	    public String toString() {
	       return code;
	    }

	    static {
	        allCodes.put(SUCCESS.getRespCode(), SUCCESS);
	        allCodes.put(ACCEPT_SUCCESS.getRespCode(), ACCEPT_SUCCESS);
	        allCodes.put(FAIL_DB_INIT.getRespCode(), FAIL_DB_INIT);
	        allCodes.put(RECORD_EXISTED.getRespCode(), RECORD_EXISTED);
	        allCodes.put(RECORD_NOT_EXIST.getRespCode(), RECORD_NOT_EXIST);
	        allCodes.put(DB_UPDATE_ZERO.getRespCode(), DB_UPDATE_ZERO);
	        allCodes.put(FAIL_DB_UPDATE.getRespCode(), FAIL_DB_UPDATE);
	        allCodes.put(FAIL_DB.getRespCode(), FAIL_DB);
	        allCodes.put(EXCEPTION_DEAL_DOING.getRespCode(), EXCEPTION_DEAL_DOING);
	        allCodes.put(EXCEPTION_DEAL_DONE.getRespCode(), EXCEPTION_DEAL_DONE);
	        allCodes.put(EXCEPTION_DEAL_FAILD.getRespCode(), EXCEPTION_DEAL_FAILD);
	        allCodes.put(HOST_RECHECK.getRespCode(), HOST_RECHECK);
	        allCodes.put(ACCT_IS_BLACK.getRespCode(), ACCT_IS_BLACK);
	        allCodes.put(ACCT_IS_EXCEPTION.getRespCode(), ACCT_IS_EXCEPTION);
	        allCodes.put(LACK_OF_BALANCE.getRespCode(), LACK_OF_BALANCE);
	        allCodes.put(LESS_CONFIGURATION.getRespCode(), LESS_CONFIGURATION);
	        allCodes.put(PASSWORD_ENCRYPT_FAIL.getRespCode(), PASSWORD_ENCRYPT_FAIL);    
	        allCodes.put(SYSTEM_FAILUE.getRespCode(), SYSTEM_FAILUE);  
	        allCodes.put(USER_NOT_EXIST.getRespCode(), USER_NOT_EXIST); 
	        allCodes.put(TELLER_IS_EXIST.getRespCode(), TELLER_IS_EXIST); 
	        allCodes.put(ORGAN_IS_EXIST.getRespCode(), ORGAN_IS_EXIST); 
	        allCodes.put(ORGAN_NOT_EXIST.getRespCode(), ORGAN_NOT_EXIST); 
	        allCodes.put(SUB_IS_EXIST.getRespCode(), SUB_IS_EXIST); 
	        allCodes.put(SUB_NOT_EXIST.getRespCode(), SUB_NOT_EXIST);
	    }
	    
	    

	    /**
	     * 通过代号获取对象
	     * 
	     * @param code
	     * @return
	     */
	    public static RespCode valueByCode(String code) {
	        return allCodes.get(code);
	    }
	    
	    
	    /**
	     * 返回码比较
	     * @param subSysRespCode
	     * @param localRespCodes
	     * @return
	     */
	    public static boolean compare(String respCode,String... localRespCodes){
	        if(StringUtils.isBlank(respCode)||localRespCodes.length==0){
	            return false;
	        }
	        boolean result=false;
	        respCode = respCode.replaceAll("[^0-9]", "");
	        
	        for(int i=0;i<localRespCodes.length;i++){
	            String localRespCode = localRespCodes[i];
	            if(StringUtils.isNotBlank(localRespCode)){
	                if(respCode.equals(localRespCode)){
	                    result= true;
	                    break;
	                }
	            }
	        }
	        return result;
	    }

}
